if ( window.profileui == undefined) {

    window.profileui = {};

    $(document).ready(function() {

        boot.ready(function(message) {

            var scoresList = new Message();
            var currentScore = new Message();
            var currentURL = null;
            scoresList.restLoad(message.restLink("currentScores"), function() {

                $.each(scoresList.messages, function() {
                    var item = new Message(this);
                    $("<li>" + this.name + "</li>").appendTo("#teamNames").click(function() {

                        currentScore.restLoad(item.restLink("self"), function(message) {

                            $("input, textarea ").val("");
                            currentURL = item.restLink("self");
                            $("#noTeam").hide();
                            $("#teamSelected").show();
                            $("#score").val(currentScore.score);
                            $("#comments").val(currentScore.comments);
                        }, function() {

                            $("input, textarea ").val("");
                            currentURL = item.restLink("self");
                            $("#noTeam").hide();
                            $("#teamSelected").show();
                            $("#score").val("");
                            $("#comments").val("");
                            currentScore = new Message();
                        })
                    });
                });
            });

            $("#saveScore").click(function() {

                currentScore.score = parseInt($("#score").val());
                currentScore.comments = $("#comments").val();
                currentScore.restCreate(currentURL, function() {

                    $("#teamSelected").hide();
                    $("#noTeam").show();
                } )
            })

        })

    })
}
